﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.Application.Services.Dto;
using Abp.AspNetCore.Mvc.Authorization;
using ABP.TPLMS.Controllers;
using ABP.TPLMS.Suppliers;
using ABP.TPLMS.Suppliers.Dto;
using ABP.TPLMS.Web.Models.Supplier;
using AutoMapper;
using Microsoft.AspNetCore.Mvc;


namespace ABP.TPLMS.Web.Controllers
{
    [AbpMvcAuthorize]
    public class SupplierController : TPLMSControllerBase
    {
        const int MaxNum = 10;
        private readonly ISupplierAppService _supplierAppService;
        private readonly IMapper _mapper;

        public SupplierController(ISupplierAppService supplierAppService ,IMapper mapper)
        {
            this._supplierAppService = supplierAppService;
            this._mapper = mapper;
        }
        // GET: /<controller>/
        public async Task<IActionResult> Index()
        {
            var module = (await _supplierAppService.GetAll(new PagedSupplierResultRequestDto { MaxResultCount = MaxNum })).Items;
            SupplierDto cuModule = module.FirstOrDefault();
            var model = new SupplierListViewModel
            {
                Supplier = cuModule,
                Suppliers = module
            };
            return View(model);
        }

        public async Task<ActionResult> EditSupplierModal(int moduleId)

        {
            var module = await _supplierAppService.Get(new EntityDto<int>(moduleId));
            CreateUpdateSupplierDto cuSupplier = _mapper.Map<CreateUpdateSupplierDto>(module);
            var model = new EditSupplierModalViewModel
            {
                Supplier = cuSupplier

            };
            return View("_EditSupplierModal", model);
        }
    }
}
